package com.springStudy.beans.factory.config.demo;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
//@Scope("prototype")
public class TestBean implements InitializingBean, DisposableBean {
    private String name;
    private int age;
    @Autowired
    private TestBean2 testBean2;

    public TestBean() {
        System.out.println("TestBean的构造方法");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        System.out.println("TestBean->setter");
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        System.out.println("TestBean->setter");
        this.age = age;
    }

    public void destroy() throws Exception {
        System.out.println("TestBean->destroy");
    }

    public void afterPropertiesSet() throws Exception {
        System.out.println("TestBean--->InitializingBean->afterPropertiesSet");
    }

    public TestBean2 getTestBean2() {
        return testBean2;
    }

    public void setTestBean2(TestBean2 testBean2) {
        System.out.println("设置 TestBean的属性TestBean2");
        this.testBean2 = testBean2;
    }
    public void initMethod(){
        System.out.println("testBean 自定义初始化函数");
    }
    public void destroyMethod(){
        System.out.println("testBean 自定义销毁函数");
    }
}